#region File Header
//-----------------------------------------------------------------------------
// SibLib
//
// Copyright (C) 2010 Julien Villers
// This program is distributed under the terms of the 
// GNU Lesser General Public License (LGPL).
// See Docs/lgpl.txt and Docs/gpl.txt
//-----------------------------------------------------------------------------
#endregion

using System;
using Microsoft.Xna.Framework.Graphics;

namespace SibLib
{
    /// <summary>
    /// Provides Color manipulation helpers.
    /// </summary>
    public static class ColorMath
    {
        /// <summary>
        /// This create a fade-in/fade-out alpha effect, with a half duration full opaque period.
        /// </summary>
        /// <param name="baseColor">The color to be faded</param>
        /// <param name="timer">Current timer value</param>
        /// <param name="period">Maximum timer value (ie period)</param>
        /// <returns></returns>
        public static Color PulseColor(Color baseColor, float timer, float period)
        {
            float colFactor = 1.0f;
            float quarterPeriod = period / 4.0f;
            if (timer < period / 4.0f)
                colFactor = 1.0f - (Math.Abs(quarterPeriod - timer) / quarterPeriod);
            else if (timer > 3.0f * quarterPeriod)
                colFactor = 1.0f - (Math.Abs((3.0f * quarterPeriod) - timer) / quarterPeriod);

            return Color.Lerp(new Color(baseColor, 80), baseColor, colFactor);
        }
    }
}